import os
import sys
import time


class Game:
    back = (115, 2638, '返回',)


class Fight:
    """战斗"""
    page = (527, 2649, 0, '战斗页',)
    game_start = (630, 2312, '开始游戏',)
    game_continue_fight = (843, 2338, '继续战斗',)
    game_back_home = (843, 2338, '战斗结束-返回战斗开始页面',)
    game_advertisement_play = (0, 0, '战斗结束-广告-播放',)
    game_advertisement_close = (0, 0, '战斗结束-广告-关闭',)

    class Fighting:
        choose_skil_one_out_of_three = (621, 1810, '选择三选一技能',)
        release_mecha = (1111, 2023, '释放机甲',)
        release_pioneer_skills = (1120, 2298, '释放先锋技能',)


class Role(Game):
    """角色"""
    page = (334, 2630, '角色页',)
    select_equipment_forging = (1026, 1136, '装备锻造')

    class EquipmentForging:
        one_reinforcement = (861, 1958, '一键强化')

    class Gemstone:
        one_click_synthesis = (1038, 1319, '一键合成')


def hit_point(point, execute_frequency=1, time_sleep=1, time_wait=1):
    """
    点击这个点
    execute_frequency   int 点击次数
    time_sleep          int 每次点击间隔
    time_wait           int 完成所有点击后等待时间
    """
    x, y, do_what = point

    for _ in range(execute_frequency):
        cmd = f'adb shell input tap {x} {y}'
        print(do_what)
        # os.system(cmd)
        time.sleep(time_sleep)
    time.sleep(time_wait)
    return None


def play_game(play_time=1):
    """打个游戏"""

    # def play_advertisement():
    #     """播放广告"""
    #     hit_point()

    for pt in range(play_time):
        hit_point(Fight.page)
        hit_point(Fight.game_back_home)
        hit_point(Fight.game_start, time_sleep=3, execute_frequency=2)
        hit_point(Fight.Fighting.choose_skil_one_out_of_three, time_sleep=1, execute_frequency=10)
        hit_point(Fight.Fighting.release_mecha)
        hit_point(Fight.Fighting.choose_skil_one_out_of_three, time_sleep=1, execute_frequency=5)
        hit_point(Fight.Fighting.release_pioneer_skills)
        hit_point(Fight.Fighting.choose_skil_one_out_of_three, time_sleep=1, execute_frequency=5)
        hit_point(Fight.Fighting.release_pioneer_skills)
        hit_point(Fight.Fighting.release_mecha)
        hit_point(Fight.Fighting.choose_skil_one_out_of_three, time_sleep=1, execute_frequency=5)
        hit_point(Fight.game_back_home)

        if pt % 5 == 0:
            strong_equipment()
            synthetic_gem()


def strong_equipment():
    """强化装备"""
    hit_point(Role.page)
    hit_point(Role.select_equipment_forging)
    hit_point(Role.EquipmentForging.one_reinforcement)
    hit_point(Role.back)


def synthetic_gem():
    """合成宝石"""
    hit_point(Role.page)
    hit_point(Role.Gemstone.one_click_synthesis)
    hit_point(Role.page)


class AimPaz:
    """向僵尸开炮"""

    def __init__(self):
        pass


if __name__ == '__main__':
    # print(Fight.Fighting.choose_skil_one_out_of_three)
    # strong_equipment()
 
    play_game(play_time=100000)
